mui.init({
	pullRefresh: {
		container: '#pullrefresh',
		up: {
			auto: true,
			contentrefresh: '正在加载...',
			callback: pullupRefresh
		}
	}
});

var userinfo = app.getState() || {};
var uid = userinfo.user_id;
var currenPage = 0;
var pageSize = 10;

mui.plusReady(function() {
	//关闭等待框
	plus.nativeUI.closeWaiting();
	//显示当前页面
	mui.currentWebview.show();
});

var count = 0;

function pullupRefresh() {
	setTimeout(function() {
		currenPage++;
		mui.ajax({
			url: apiurl + "Trade/kaplog/",
			data: {
				user_id: uid,
				'p': currenPage,
				'size': pageSize,
				'_token': userinfo.token
			},
			async: true,
			dataType: 'json',
			crossDomain: true, //强制使用5+跨域
			type: 'get',
			timeout: 10000,
			success: function(res) {
				console.log(JSON.stringify(res));
				// 请求成功
				if(res.status == -3) {
					mui.toast(res.msg);
					app.out();
					return false;
				} else {
					var add = template('list-template', {
						"tradelist": res.data
					});

					$('#pullrefresh .mui-scroll ul').append(add);
				}

				if(res.data.length == pageSize) {
					mui('#pullrefresh').pullRefresh().endPullupToRefresh(false); /*能上拉*/
				} else {
					mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); /*不能上拉*/
				}
			},
			error: function(xhr, type, errorThrown) {
				mui.toast('获取数据失败！');
			}
		});

	}, 1500);
}